<table class="layui-hide" id="Doctor" lay-filter="tblDoc"></table>
<script type="text/html" id="toolbarDemo">
      <div class="layui-btn-container">
        <button class="layui-btn layui-btn-sm" lay-event="btnUpdateDoc">修改</button>
        <button class="layui-btn layui-btn-sm" lay-event="btnAddDoc">新增</button>
        <button class="layui-btn layui-btn-sm" lay-event="btnDeleteDoc">删除</button>
      </div>
    </script>


<script>
  var data = null;
  var table = null;
  layui.use(['table', 'jquery'], function () {
    table = layui.table;
    var $ = layui.jquery;
    table.render({
      elem: '#Doctor'
      , url: 'http://localhost:8080/mid/getDoc'
      , toolbar: '#toolbarDemo'
      , defaultToolbar: ['filter', 'exports', 'print', {
        title: '提示'
        , layEvent: 'LAYTABLE_TIPS'
        , icon: 'layui-icon-tips'
      }]
      , cols: [[

        { type: 'checkbox' }
        , { field: 'doctorId', title: '医生编号' }
        , { field: 'doctorName', title: '医生姓名' }
        , { field: 'doctorLevel', title: '级别' }
        , { field: 'doctorDepartment', title: '科室' }
        , { field: 'doctorState', title: '空闲/忙碌' }

      ]]
      , page: true
      , limit: 5
      , limits: [5, 10, 15, 20]
    });


    table.on('toolbar(tblDoc)', function (obj) {
      var checkStatus = table.checkStatus(obj.config.id);
      switch (obj.event) {
        case 'btnUpdateDoc':
          if (checkStatus.data.length > 0) {
            data = checkStatus.data[0];

            layer.open({
              type: 2
              , title: '修改医生信息'
              , area: ['400px', '600px']
              , shade: 0.5
              , maxmin: true

              , content: 'docUpdate.html'

              , yes: function () {
                $(that).click();
              }
              , btn2: function () {
                layer.closeAll();
              }

              , zIndex: layer.zIndex
              , success: function (layero) {
                layer.setTop(layero);
              }
            });
          } else {
            layer.msg("请选择要修改的信息");
          }
          break;
        case 'btnAddDoc':

          layer.open({
            type: 2
            , title: '添加医生'
            , area: ['400px', '600px']
            , shade: 0.5
            , maxmin: true
            , content: 'docAdd.html'

            , yes: function () {
              $(that).click();
            }
            , btn2: function () {
              layer.closeAll();
            }
          });
          break;
        case 'btnDeleteDoc':
          layer.confirm('确认要删除选中的信息吗?', function (index) {
            if (checkStatus.data.length > 0) {
              var arr = checkStatus.data;
              var arrDocId = [];

              for (var i = 0; i < arr.length; i++) {
                var docId = arr[i].doctorId;
                arrDocId.push(DocId);
              }

              $.ajax({
                url: '',
                type: 'post',
                dataType: 'JSON',
                data: {
                  DocIds: arrDocId.join(",")
                },
                success: function (result) {

                  var index = parent.layer.getFrameIndex(window.name);
                  parent.layer.close(index);

                  parent.table.reload("Doctor", {
                    page: {
                      curr: 1
                    }
                  });
                }
              })

            } else {
              layer.msg("请选择要删除的行");
            }

            layer.close(index);
          });
          break;

      };
    });
  });


</script>